#include "NpLogger.h"
#include <string>
#include <stdlib.h>
#include <exception/NpException.h>
#include <log4cxx/xml/domconfigurator.h>

using namespace std;
using namespace log4cxx;
using namespace log4cxx::xml;
using namespace npexception;

static char g_log4cxxEnv[] = "NP_CONFIG";
static char g_confFileName[] = "log4cxx.xml";

NpLogger::NpLogger()
{
  char* path = getenv(g_log4cxxEnv);
  throwExIf(path == NULL, INVALID_LOG_CONG_ENV);

  DOMConfigurator::configure(string(path) + "/" + g_confFileName);

  m_logger = Logger::getLogger("netpipe");
}

NpLogger* NpLogger::getInstance()
{
  static NpLogger* singleton = new NpLogger();
  return singleton;
}

void NpLogger::infoLog(const char *msg)
{
  LOG4CXX_INFO(m_logger, msg);
}

void NpLogger::errLog(const char *msg)
{
  LOG4CXX_ERROR(m_logger, msg);
}

void NpLogger::debugLog(const char *msg)
{
  LOG4CXX_DEBUG(m_logger, msg);
}
